import 'package:app_30/home/vm/fencheng_list_vm.dart';
import 'package:app_30/models/detail_entity.dart';
import 'package:app_30/res/colors.dart';
import 'package:app_30/widgets/my_app_bar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';


class FenchengListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    return ViewModelBuilder<FenChengListViewModel>.reactive(
    viewModelBuilder: () => FenChengListViewModel(),
    onModelReady: (viewModel) => viewModel.initialise(),
    builder: (context, viewModel, child) => Scaffold(
      appBar: MyAppBar(
        isBack: true,
        centerTitle: '分成记录',
      ),
      body:  ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          DetailEntity data = viewModel.data[index];
          return Container(
            padding: EdgeInsets.all(10),
            child: Column(
              children: [
                buildRow("结算账号：", data.txzh!),
                buildRow("提现时间：", data.txtime!),
                buildRow("结算时间：", data.endtime!),
                buildRow2("状态：", data.txend!),
                SizedBox(
                  height: 5,
                ),
                SizedBox(
                  width: double.infinity,
                  height: 1,
                  child: Container(
                    color: Colors.grey,
                  ),
                ),
              ],
            ),
          );
        },
        itemCount: viewModel.data.length,
      ),
    ));
  }

  Container buildRow(title, text) {
    return Container(
      padding: EdgeInsets.only(bottom: 2),
      child: Row(mainAxisSize: MainAxisSize.max, children: [
        SizedBox(
          width: 70,
          child: Text(
            title,
            style: TextStyle(color: Colors.grey, fontSize: 14),
          ),
        ),
        Text(text, style: TextStyle(color: Colors.grey, fontSize: 12))
      ]),
    );
  }

  Container buildRow2(title, text) {
    return Container(
      padding: EdgeInsets.only(bottom: 2),
      child: Row(
        mainAxisSize: MainAxisSize.max,
        children: [
          SizedBox(
            width: 70,
            child: Text(
              title,
              style: TextStyle(color: Colors.grey, fontSize: 14),
            ),
          ),
          Container(
            padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
            decoration: BoxDecoration(
              color: Colours.app_main,
              shape: BoxShape.rectangle,
              borderRadius: BorderRadius.circular(5.0),
            ),
            child: Padding(
              padding: EdgeInsets.all(3),
              child: Row(mainAxisSize: MainAxisSize.min, children: [
                Text(
                  text,
                  textAlign: TextAlign.left,
                  style: TextStyle(fontSize: 12, color: Colors.white),
                )
              ]),
            ),
          ),
        ],
      ),
    );
  }
}
